package com.ruoyi.asset.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.asset.domain.FlowCheck;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AssetFlowCheck;
import com.ruoyi.asset.service.IAssetFlowCheckService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审核流程Controller
 * 
 * @author yepanpan
 * @date 2024-12-20
 */
@RestController
@RequestMapping("/asset/flowCheck")
public class AssetFlowCheckController extends BaseController
{
    @Autowired
    private IAssetFlowCheckService assetFlowCheckService;

    /**
     * 查询审核流程列表
     */
    @GetMapping("/my")
    public TableDataInfo my(AssetFlowCheck assetFlowCheck)
    {
        if(assetFlowCheck.getCheckStatus() == null){
            assetFlowCheck.setCheckStatus(FlowCheck.CHECK_UNDO);
        }
        assetFlowCheck.setCheckUserId(SecurityUtils.getUserId());
        startPage();
        List<AssetFlowCheck> list = assetFlowCheckService.selectAssetFlowCheckList(assetFlowCheck);
        return getDataTable(list);
    }

    /**
     * 查询审核流程列表
     */
    @PreAuthorize("@ss.hasPermi('asset:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetFlowCheck assetFlowCheck)
    {
        startPage();
        List<AssetFlowCheck> list = assetFlowCheckService.selectAssetFlowCheckList(assetFlowCheck);
        return getDataTable(list);
    }

    /**
     * 导出审核流程列表
     */
    @PreAuthorize("@ss.hasPermi('asset:check:export')")
    @Log(title = "审核流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetFlowCheck assetFlowCheck)
    {
        List<AssetFlowCheck> list = assetFlowCheckService.selectAssetFlowCheckList(assetFlowCheck);
        ExcelUtil<AssetFlowCheck> util = new ExcelUtil<AssetFlowCheck>(AssetFlowCheck.class);
        util.exportExcel(response, list, "审核流程数据");
    }

    /**
     * 获取审核流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetFlowCheckService.selectAssetFlowCheckById(id));
    }

    /**
     * 新增审核流程
     */
    @PreAuthorize("@ss.hasPermi('asset:check:add')")
    @Log(title = "审核流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetFlowCheck assetFlowCheck)
    {
        return toAjax(assetFlowCheckService.insertAssetFlowCheck(assetFlowCheck));
    }

    /**
     * 修改审核流程
     */
    @PreAuthorize("@ss.hasPermi('asset:check:edit')")
    @Log(title = "审核流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetFlowCheck assetFlowCheck)
    {
        return toAjax(assetFlowCheckService.updateAssetFlowCheck(assetFlowCheck));
    }

    /**
     * 删除审核流程
     */
    @PreAuthorize("@ss.hasPermi('asset:check:remove')")
    @Log(title = "审核流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetFlowCheckService.deleteAssetFlowCheckByIds(ids));
    }

    /**
     * 提交到审核流程
     */
    @Log(title = "审核流程", businessType = BusinessType.INSERT)
    @GetMapping("submit/{flowId}")
    public AjaxResult submit(@PathVariable("flowId") Long flowId)
    {
        return toAjax(assetFlowCheckService.submitAssetFlowCheck(flowId));
    }


    /**
     * 批量审核
     */
    @Log(title = "审核流程", businessType = BusinessType.UPDATE)
    @PostMapping("batch")
    @PreAuthorize("@ss.hasPermi('asset:flow:check')")
    public AjaxResult batch(@RequestBody FlowCheck flowCheck)
    {
        return toAjax(assetFlowCheckService.batchCheckAssetFlow(flowCheck));
    }

    /**
     * 批量审核
     */
    @Log(title = "审核流程", businessType = BusinessType.UPDATE)
    @PostMapping("check")
    @PreAuthorize("@ss.hasPermi('asset:flow:check')")
    public AjaxResult check(@RequestBody FlowCheck flowCheck)
    {
        return toAjax(assetFlowCheckService.checkAssetFlow(flowCheck));
    }
}
